From 438c08438272c035b36ff6dcc722bb6bfa674a8e Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 10 Feb 2013 06:02:10 +0000 Subject: [PATCH] Beging the long, hard road of moving core structures from char * to QString. Mostly, this just compartmentalizes the pain of character set conversions in xmlgeneric.cc while letting them accpet QStrings. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4302 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/cet_util.cc | 5 +++++ gpsbabel/cet_util.h | 1 + gpsbabel/defs.h | 4 ++-- gpsbabel/garmin_txt.cc | 6 ++++++ gpsbabel/gbfile.cc | 5 +++++ gpsbabel/gbfile.h | 1 + gpsbabel/gdb.cc | 6 ++++++ gpsbabel/xmlgeneric.cc | 44 +++++++++++++++++++++--------------------- gpsbabel/xmlgeneric.h | 25 ++++++++++++------------ 9 files changed, 61 insertions(+), 36 deletions(-) diff --git a/gpsbabel/cet_util.cc b/gpsbabel/cet_util.cc index 3bdb49a45..54b0e0898 100644 --- a/gpsbabel/cet_util.cc +++ b/gpsbabel/cet_util.cc @@ -1020,6 +1020,11 @@ cet_convert_string(char* str) return res; } +const char * +cet_convert_string(QString str) { + return cet_convert_string(str.toUtf8().data()); +} + /* cet_convert_waypt: internal used within cet_convert_strings process */ static void diff --git a/gpsbabel/cet_util.h b/gpsbabel/cet_util.h index abb5d3345..e01a73ef4 100644 --- a/gpsbabel/cet_util.h +++ b/gpsbabel/cet_util.h @@ -109,6 +109,7 @@ int cet_gbfprintf(gbfile* stream, const cet_cs_vec_t* src_vec, const char* fmt, /* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */ char* cet_convert_string(char* str); +const char* cet_convert_string(QString str); /* gpsbabel extensions */ diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index aa547669a..5a1caf099 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -375,7 +375,7 @@ class url_link { url(NULL), url_link_text(NULL) {} ; - struct url_link* url_next; + url_link* url_next; char* url; char* url_link_text; }; @@ -539,7 +539,7 @@ public: * We also use an implicit anonymous union here, so these three * members must match struct url_link... */ - struct url_link* url_next; + url_link* url_next; char* url; char* url_link_text; diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index 9c8ad1edc..22a66d3b2 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -523,6 +523,12 @@ print_string(const char* fmt, const char* string) xfree(buff); } +static void +print_string(const char* fmt, const QString string) +{ + print_string(fmt, string.toUtf8().data()); +} + /* main cb's */ diff --git a/gpsbabel/gbfile.cc b/gpsbabel/gbfile.cc index 376d2b2c8..e85d5622e 100644 --- a/gpsbabel/gbfile.cc +++ b/gpsbabel/gbfile.cc @@ -1226,6 +1226,11 @@ gbfputcstr(const char* s, gbfile* file) return 1; } } +int +gbfputcstr(const QString s, gbfile* file) +{ + return gbfputcstr(qPrintable(s), file); +} /* * gbfputcstr: write a pascal string into a stream diff --git a/gpsbabel/gbfile.h b/gpsbabel/gbfile.h index f4ed58e41..7b9a05b9c 100644 --- a/gpsbabel/gbfile.h +++ b/gpsbabel/gbfile.h @@ -130,6 +130,7 @@ int gbfputint32(const gbint32 i, gbfile* file); int gbfputdbl(const double d, gbfile* file); // write a double value int gbfputflt(const float f, gbfile* file); // write a float value int gbfputcstr(const char* s, gbfile* file); // write string including '\0' +int gbfputcstr(const QString s, gbfile* file); // write string including '\0' int gbfputpstr(const char* s, gbfile* file); // write as pascal string gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count); diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index 0e5d6af4e..2227f1705 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -391,6 +391,12 @@ gdb_write_cstr_list(const char* str) } } +static void +gdb_write_cstr_list(const QString str) +{ + return gdb_write_cstr_list(str.toAscii().data()); +} + static void gdb_write_dbl(const double value, const double def) { diff --git a/gpsbabel/xmlgeneric.cc b/gpsbabel/xmlgeneric.cc index 70703097f..4c99ce3e8 100644 --- a/gpsbabel/xmlgeneric.cc +++ b/gpsbabel/xmlgeneric.cc @@ -53,52 +53,52 @@ write_xml_header(gbfile *ofd) } void -write_xml_entity(gbfile *ofd, const char *indent, - const char *tag, const char *value) +write_xml_entity(gbfile *ofd, QString indent, + QString tag, QString value) { - char *tmp_ent = xml_entitize(value); - gbfprintf(ofd, "%s<%s>%s\n", indent, tag, tmp_ent, tag); + char *tmp_ent = xml_entitize(value.toAscii().data()); + gbfprintf(ofd, "%s<%s>%s\n", qPrintable(indent), qPrintable(tag), tmp_ent, qPrintable(tag)); xfree(tmp_ent); } void -write_optional_xml_entity(gbfile *ofd, const char *indent, - const char *tag, const char *value) +write_optional_xml_entity(gbfile *ofd, const QString indent, + const QString tag, const QString value) { - if (value && *value) { + if (!value.isEmpty()) { write_xml_entity(ofd, indent, tag, value); } } void -write_xml_entity_begin0(gbfile *ofd, const char *indent, - const char *tag) +write_xml_entity_begin0(gbfile *ofd, const QString indent, + const QString tag) { - gbfprintf(ofd, "%s<%s>\n", indent, tag); + gbfprintf(ofd, "%s<%s>\n", indent.toAscii().data(), tag.toAscii().data()); } void -write_xml_entity_begin1(gbfile *ofd, const char *indent, - const char *tag, const char *attr, - const char *attrval) +write_xml_entity_begin1(gbfile *ofd, const QString indent, + const QString tag, const QString attr, + const QString attrval) { - gbfprintf(ofd, "%s<%s %s=\"%s\">\n", indent, tag, attr, attrval); + gbfprintf(ofd, "%s<%s %s=\"%s\">\n", indent.toAscii().data(), tag.toAscii().data(), attr.toAscii().data(), attrval.toAscii().data()); } void -write_xml_entity_begin2(gbfile *ofd, const char *indent, - const char *tag, const char *attr1, - const char *attrval1, const char *attr2, - const char *attrval2) +write_xml_entity_begin2(gbfile *ofd, const QString indent, + const QString tag, const QString attr1, + const QString attrval1, const QString attr2, + const QString attrval2) { - gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent, tag, attr1, attrval1, attr2, attrval2); + gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent.toAscii().data(), tag.toAscii().data(), attr1.toAscii().data(), attrval1.toAscii().data(), attr2.toAscii().data(), attrval2.toAscii().data()); } void -write_xml_entity_end(gbfile *ofd, const char *indent, - const char *tag) +write_xml_entity_end(gbfile *ofd, const QString indent, + const QString tag) { - gbfprintf(ofd, "%s\n", indent, tag); + gbfprintf(ofd, "%s\n", indent.toAscii().data(), tag.toAscii().data()); } void diff --git a/gpsbabel/xmlgeneric.h b/gpsbabel/xmlgeneric.h index 6252c6cae..27e2b69ae 100644 --- a/gpsbabel/xmlgeneric.h +++ b/gpsbabel/xmlgeneric.h @@ -37,19 +37,20 @@ typedef struct xg_tag_mapping { extern char* xhtml_entities; -void write_xml_entity(gbfile* ofd, const char* indent, - const char* tag, const char* value); -void write_xml_entity_begin0(gbfile* ofd, const char* indent, - const char* tag); -void write_xml_entity_begin1(gbfile* ofd, const char* indent, const char* tag, - const char* attr1, const char* attrval1); -void write_xml_entity_begin2(gbfile* ofd, const char* indent, const char* tag, - const char* attr1, const char* attrval1, - const char* attr2, const char* attrval2); -void write_xml_entity_end(gbfile* ofd, const char* indent, const char* tag); +void write_xml_entity(gbfile* ofd, const QString indent, + const QString tag, const QString value); +void write_xml_entity_begin0(gbfile* ofd, const QString indent, + const QString tag); +void write_xml_entity_begin1(gbfile* ofd, const QString indent, + const QString tag, const QString attr1, + const QString attrval1); +void write_xml_entity_begin2(gbfile* ofd, const QString indent, const QString tag, + const QString attr1, const QString attrval1, + const QString attr2, const QString attrval2); +void write_xml_entity_end(gbfile* ofd, const QString indent, const QString tag); -void write_optional_xml_entity(gbfile* ofd, const char* indent, - const char* tag, const char* value); +void write_optional_xml_entity(gbfile* ofd, const QString ndent, + const QString tag, const QString value); void xml_write_time(gbfile* ofd, const time_t timep, int microseconds, const char* elname); void xml_fill_in_time(char* time_string, const time_t timep, int microseconds, int long_or_short); -- 2.30.2